// 加载路径模块
const path = require("path");
// 不打包node
const nodeExternals = require('webpack-node-externals')

module.exports = {
  target: "node",
  mode: "development",
  entry: {
    server: {
      import: "./src/server/index.ts",
      filename: "server.js",
    },
  },
  output: {
    filename: "[name].js",
    path: path.resolve(process.cwd(), "dist"),
    chunkFormat: "commonjs",
    libraryTarget: "commonjs2"
  },
  optimization: {
    minimize: false,
  },
  resolve: {
    extensions: [".js", ".json", ".ts"],
  },
  module: {
    rules: [
      // script 处理
      {
        test: /\.(ts|js)$/,
        use: [
          {
            loader: "esbuild-loader",
            options: {
              loader: "ts",
            },
          },
        ],
      }
    ],
  },
  externalsPresets: { node: true },
  externals: [
    nodeExternals()
  ],
  devtool: "cheap-module-source-map"
};
